package com.xing.service.impl;

import com.xing.core.BaseServiceImpl;
import com.xing.dao.ChatHistoryDao;
import com.xing.dto.ChatHistoryDTO;
import com.xing.dto.ChatUserDTO;
import com.xing.entity.ChatHistoryEntity;
import com.xing.service.ChatHistoryService;
import com.xing.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2024/4/23 14:47
 */
@Service
public class ChatHistoryServirImpl extends BaseServiceImpl<ChatHistoryDao, ChatHistoryEntity> implements ChatHistoryService {
    @Autowired
    private ChatHistoryDao dao;

    @Override
    public List<ChatHistoryDTO> getChatHistory(Long attentionedId,Integer limit) {
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<ChatHistoryDTO> chatHistory = dao.getChatHistory(user.getId(), attentionedId,limit);
        return chatHistory;
    }

    @Override
    public List<ChatUserDTO> getChatUser() {
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return dao.getUsers(user.getId());
    }
}
